<?php
/**
 * @version		$Id: mod_vinaora_slickshow.php 2011-07-05 vinaora $
 * @package		VINAORA SLICK SLIDESHOW
 * @subpackage	mod_vinaora_slickshow
 * @copyright	Copyright (C) 2010 - 2011 VINAORA. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 * @website		http://vinaora.com
 * @twitter		http://twitter.com/vinaora
 * @facebook	http://facebook.com/vinaora
 */

// no direct access
defined('_JEXEC') or die;

define( 'MEDIA_URL', 'media/mod_vinaora_slickshow/' );
define( 'AJAX_SWFOBJECT_URL', 'http://ajax.googleapis.com/ajax/libs/swfobject/' );

// Require Base Helper
require_once dirname(__FILE__).DS.'helper.php';

// Valid the parameters
$params = &extVinaoraParam::validParams($params);

// Choose items from a directory
$directory = $params->get('item_dir');

// Overwrite 'item_path' parameter
if ( $directory != '-1' ){
	$item_paths = modVinaoraSlickshowHelper::getItemPaths($directory);
	$item_paths = implode("\n", $item_paths);
	$params->set( 'item_path', $item_paths );
}

$config_custom		= $params->get( 'config_custom' );
$config_name 		= $params->get( 'config_code' );

$config_name		= ($config_name) ? $config_name : "demo1.xml.php";
$config_name		= ($config_custom=="-1") ? $config_name : $config_custom;

// Check Dimesion Stage
$param = abs(intval($params->get("width")));
$params->set("width", $param);

$param = abs(intval($params->get("height")));
$params->set("height", $param);

// Check Background Color
$param = extVinaoraParam::validColor($params->get("backgroundColor"), "ffffff", "0x");
$params->set("backgroundColor", $param);

// Check Background Transparency
$param = extVinaoraParam::validTransparency($params->get("backgroundTransparency"));
$params->set("backgroundTransparency", $param);

// Check StartWith
$param = abs(intval($params->get("startWith")));
$params->set("startWith", $param);

// Check Navigation Bar Height
$param = abs(intval($params->get("barHeight")));
$params->set("barHeight", $param);

// Check Navigation Bar Color
$param = extVinaoraParam::validColor($params->get("barColor"), "ffffff", "0x");
$params->set("barColor", $param);

// Check Navigation Bar Transparency
$param = extVinaoraParam::validTransparency($params->get("barTransparency"));
$params->set("barTransparency", $param);

// Check FadeTransition
$param = $params->get("fadeTransition") ? "true" : "false";
$params->set("fadeTransition", $param);

// Check VerticalTransition
$param = $params->get("verticalTransition") ? "true" : "false";
$params->set("verticalTransition", $param);

// Check ControllerTop
$param = $params->get("controllerTop") ? "true" : "false";
$params->set("controllerTop", $param);

// Check Slideshow Time
$param = abs(intval($params->get("slideShowTime")));
$params->set("slideShowTime", $param);

// Check Config file (.xml) exits and valid XML
$config_name = MEDIA_URL.'config/'.$config_name;

$config = modVinaoraSlickshowHelper::getConfig($config_name);

// Config File exist and valid
if ( $config ){

	// Get the size of stage flash
	$param	= $config->attributes()->width;
	$params->set('width', $param);
	
	$param	= $config->attributes()->height;
	$params->set('height', $param);
	
	$param	= $config->attributes()->backgroundColor;
	$params->set('backgroundColor', $param);
}
// Config File not exist
else{
	modVinaoraSlickshowHelper::createConfig($config_name, $params);
}

// Add SWFObject Library to <head> tag
extVinaoraParam::addSWFObject( $params->get('swfobject') );

// Get flash params
$flash_wmode	= $params->get( 'flash_wmode' );

// Initialize variables
$media					= JURI::base(true)."/".MEDIA_URL;
$config_path 			= JURI::base(true)."/".$config_name;
$stage_path 			= $media.'flash/vinaora_slickshow.swf';
$expressInstall_path 	= $media.'js/swfobject/expressInstall.swf';
$flash_version			= '9.0.124';

$width					= $params->get( 'width' );
$height					= $params->get( 'height' );
$backgroundColor		= $params->get( 'backgroundColor' );
$backgroundColor		= extVinaoraParam::validColor($backgroundColor, "ffffff", "#");

$moduleclass_sfx		= htmlspecialchars( trim($params->get( 'moduleclass_sfx' )) );

$module_id				= $module->id;
$container				= 'vinaora-slick-slideshow'.$module_id;

// Add Custom CSS to <head> tag
$document = JFactory::getDocument();

$css= "\n\t".'<style type="text/css">'
	. "\n\t".'#'.$container.' {width:'.$width.'px; outline:0;}'
	. "\n  ".'</style>';

$document->addCustomTag($css);

// Load Default Layout
require JModuleHelper::getLayoutPath('mod_vinaora_slickshow', $params->get('layout', 'default'));
